//=============================================================================
//
//   Copyright (C) 2020 All rights reserved.
//
//   Filename:		time_func_interface.rs
//
//   Author: Wang Zhecheng - wangzhecheng@yeah.net
//
//   Date: 2020-10-08 01:17
//
//   Last Editors: Wang Zhecheng - wangzhecheng@yeah.net
//
//   Last modified:	2020-11-06 18:27
//
//   Description:
//
//=============================================================================
use crate::Real;

pub trait TimeFuncInterface: std::fmt::Debug {
    /// return value of function at given time step
    fn get_value_at(&self, ctime: Real) -> Real;

    /// return slope of function at given time step
    #[inline]
    fn get_increment_between(&self, stime: Real, etime: Real) -> Real {
        self.get_value_at(etime) - self.get_value_at(stime)
    }

    /// return acceleration of function at given time step
    #[inline]
    fn get_slope_at(&self, ctime: Real) -> Real {
        let dt = ctime.max(1e-3) * 0.1;
        (self.get_value_at(ctime + dt) - self.get_value_at(ctime - dt)) / 2 as Real / dt
    }
}
